package project.youkumenu.utils;

import android.animation.ObjectAnimator;
import android.view.View;

/**
 * Created by lgs on 2018/3/7.
 */

public class ShowViewUtils {

    public static void hideView(View view) {
        hideView(view, 0);
    }

    public static void showView(View view) {
        showView(view, 0);
    }

    public static void hideView(View view, long startOffset) {
        //        RotateAnimation ra = new RotateAnimation(0f, 180f, view.getMeasuredWidth() / 2, view.getMeasuredHeight());
        //        ra.setDuration(500);    //设置动画播放持续的时间
        //        ra.setFillAfter(true);  //动画停留在播放完成的状态
        //        ra.setStartOffset(startOffset); //动画延迟播放
        //        view.startAnimation(ra);

        //        ObjectAnimator animator = new ObjectAnimator();
        //        animator.ofFloat(view, "rotation", 180f, 360f);
        ObjectAnimator animator = ObjectAnimator.ofFloat(view, "rotation", 0f, 180f)
                .setDuration(500);
        animator.setStartDelay(startOffset);
        animator.start();

        //设置旋转中心
        view.setPivotX(view.getWidth() / 2);
        view.setPivotY(view.getHeight());
    }

    public static void showView(View view, long startOffset) {
        //旋转动画默认相对于自己
       /* RotateAnimation ra = new RotateAnimation(180f, 360f, view.getMeasuredWidth() / 2, view.getMeasuredHeight());
        ra.setDuration(500);    //设置动画播放持续的时间
        ra.setFillAfter(true);  //动画停留在播放完成的状态
        ra.setStartOffset(startOffset); //动画延迟播放
        view.startAnimation(ra);*/


        //        ObjectAnimator objectAnimator = new ObjectAnimator();
        //        ObjectAnimator.ofFloat(view, "rotationY", 180f, 360f)
        //        .setDuration(500)
        //        .setStartDelay(startOffset);
        ObjectAnimator animator = ObjectAnimator.ofFloat(view, "rotation", 180f, 360f)
                .setDuration(500);
        animator.setStartDelay(startOffset);
        animator.start();

        //设置旋转中心
        view.setPivotX(view.getWidth() / 2);
        view.setPivotY(view.getHeight());

    }
}
